#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <algorithm>
#include <cassert>

int n, m;

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	std::cout.tie(nullptr);

	std::freopen("bishop.in", "r", stdin);
	std::freopen("bishop.out", "w", stdout);

	std::cin >> n >> m;
	std::vector<std::pair<int, int>> ans;
	bool swapped = 0;
	if(n < m) std::swap(n, m), swapped = 1;
	for(int d = 0; d < 2; ++d) {
		std::vector<std::pair<std::pair<int, int>, int>> ranges;
		for(int i = 1; i <= n; ++i) if((1 + i) % 2 == d) {
			//(i, 1)
			//x + y = i + 1
			int x = 0, y = 0;
			if(i <= m) x = 1, y = i;
			else x = i - m + 1, y = m;
			int l = std::min(i - 1, x - y);
			int r = std::max(i - 1, x - y);
			ranges.emplace_back(std::make_pair(l, r), i + 1);
		}
		for(int i = 2; i <= m; ++i) if((n + i) % 2 == d) {
			//(n, i)
			//x + y = n + i
			int x = n + i - m, y = m;
			int l = std::min(n - i, x - y);
			int r = std::max(n - i, x - y);
			ranges.emplace_back(std::make_pair(l, r), n + i);
		}
		std::priority_queue<std::pair<int, int>, std::vector<std::pair<int, int>>, std::greater<std::pair<int, int>>> pq;
		std::sort(ranges.begin(), ranges.end());
		int p = 0;
		int limit = n + m;
		if(limit % 2 != d) ++limit;
		for(int i = -limit; i <= limit; i += 2) {
			while(p < ranges.size() && ranges[p].first.first == i) pq.emplace(ranges[p].first.second, ranges[p].second), ++p;
			while(!pq.empty() && pq.top().first < i) pq.pop();
			if(!pq.empty()) {
				int k = pq.top().second; pq.pop();
				int x = (i + k) / 2, y = (k - i) / 2;
				assert(1 <= x && x <= n);
				assert(1 <= y && y <= m);
				ans.emplace_back(x, y);
			}
		}
	}
	std::cout << ans.size() << "\n";
	for(auto e : ans) {
		if(swapped) std::swap(e.first, e.second);
		std::cout << e.first << " " << e.second << "\n";
	}
	std::vector<int> v1, v2;
	for(auto e : ans) {
		v1.push_back(e.first + e.second);
		v2.push_back(e.first - e.second);
	}
	std::sort(v1.begin(), v1.end());
	std::sort(v2.begin(), v2.end());
	for(int i = 1; i < v1.size(); ++i) assert(v1[i] != v1[i-1]);
	for(int i = 1; i < v2.size(); ++i) assert(v2[i] != v2[i-1]);

	return 0;
}
